import pygame
from random import *
from commonModule import *


# 小型敌机
class SmallEnemy(pygame.sprite.Sprite):
    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/enemy1.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size
        self.rect.left, self.rect.top = randint(
            0, self.width-self.rect.width), randint(-5*self.height, 0)
        self.speed = 2
        # 添加被撞毁图片
        self.destore_images = [loadImage('enemy1_down1.png'), loadImage(
            'enemy1_down2.png'), loadImage('enemy1_down3.png'), loadImage('enemy1_down4.png')]
        self.active = True
        self.mask = pygame.mask.from_surface(self.image)

    # 飞机移动
    def move(self):
        self.rect.top += self.speed
        if self.rect.top > self.height:
            self.reset()

    # 重置飞机
    def reset(self):
        self.active = True
        self.rect.left, self.rect.top = randint(
            0, self.width-self.rect.width), randint(-5*self.height, 0)


# 中型敌机
class MidEnemy(pygame.sprite.Sprite):
    energy = 8

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/enemy2.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size
        self.rect.left, self.rect.top = randint(
            0, self.width-self.rect.width), randint(-10*self.height, -self.height)
        self.speed = 1
        # 添加被撞毁图片
        self.destore_images = [loadImage('enemy2_down1.png'), loadImage(
            'enemy2_down2.png'), loadImage('enemy2_down3.png'), loadImage('enemy2_down4.png')]
        self.active = True
        self.mask = pygame.mask.from_surface(self.image)
        self.energy = MidEnemy.energy
        # 是否被子弹击中
        self.hit = False
        self.hit_image = loadImage("enemy2_hit.png")

    # 飞机移动
    def move(self):
        self.rect.top += self.speed
        if self.rect.top > self.height:
            self.reset()

    # 重置飞机
    def reset(self):
        self.active = True
        self.rect.left, self.rect.top = randint(
            0, self.width-self.rect.width), randint(-10*self.height, -self.height)
        self.energy = MidEnemy.energy
        self.hit = False


# 大型敌机
class BigEnemy(pygame.sprite.Sprite):
    energy = 8

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(
            "./images/enemy3_n1.png").convert_alpha()
        self.image2 = pygame.image.load(
            "./images/enemy3_n2.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size
        self.rect.left, self.rect.top = randint(
            0, self.width-self.rect.width), randint(-10*self.height, -self.height)
        self.speed = 1
        # 添加被撞毁图片
        self.destore_images = [loadImage('enemy3_down1.png'), loadImage(
            'enemy3_down2.png'), loadImage('enemy3_down3.png'), loadImage('enemy3_down4.png')]
        self.active = True
        self.mask = pygame.mask.from_surface(self.image)
        self.energy = BigEnemy.energy
        # 是否被子弹击中
        self.hit = False
        self.hit_image = loadImage("enemy3_hit.png")

    # 飞机移动
    def move(self):
        self.rect.top += self.speed
        if self.rect.top > self.height:
            self.reset()

    # 重置飞机
    def reset(self):
        self.active = True
        self.rect.left, self.rect.top = randint(
            0, self.width-self.rect.width), randint(-10*self.height, -self.height)
        self.energy = BigEnemy.energy
        self.hit = False
